from pprint import PrettyPrinter
#number of iterations
iter_num = 50
#upper limit
lim = 10000
#array of lychrels (to test values which already known to produce polyndrome)
non_lychrels = []
def reverse_num(num):
 'returns reversed value of a num'
 return int(''.join(list(reversed(str(num)))))
def is_polyndrome(num):
 return num == reverse_num(num)
def is_lychrel(num):   
 l_arr = []
 l_n = num
 if l_n in non_lychrels:
  return 0
 else:
  for i in range(iter_num):
   #Exceptions are lychrel numbers which are polyndrome, ie 4994
   if is_polyndrome(l_n) and l_n <> num:
    non_lychrels.append(l_arr)
    return 0
   else:
    l_arr.append(l_n)
    l_arr.append(reverse_num(l_n))
    l_n = l_n + reverse_num(l_n)
  #print 'Array len: ', len(l_arr), ' : ', l_arr
  return 1

# debug
#is_lychrel(9999)
#---------------------------------------------------------------#
lychrels = [x for x in range(1,lim) if is_lychrel(x)]
printer = PrettyPrinter()
printer.pprint(lychrels)
print "count:",len(lychrels)
#---------------------------------------------------------------#



